<template>
  <div class="albumContainer">
    <div class="preview">
      <img :src="getUrl(goodsimage[selectIndex])" alt="" />
    </div>
    <div class="albumList">
      <div
        v-for="(item, index) in goodsimage"
        :key="index"
        :class="['albumLi', index == selectIndex ? 'active' : '']"
        @click="handleClick(index)"
      >
        <img :src="getUrl(item)" alt="" />
      </div>
    </div>
  </div>
</template>

<script>
import { baseURL } from "@/http";
export default {
  props: {
    goodsimage: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      selectIndex: 0,
    };
  },
  methods: {
    handleClick(index) {
      this.selectIndex = index;
      console.log(index);
    },
    getUrl(url) {
      if (url && url.indexOf("http") > -1) return url;
      return baseURL + url;
    },
  },
};
</script>

<style lang="less" scoped>
.albumContainer {
  padding: 20px;
  .preview {
    width: 400px;
    height: 400px;
    border: 1px solid #333;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .albumList {
    display: flex;
    justify-content: center;
    margin-top: 20px;
    .albumLi {
      margin: 0 5px;
      width: 50px;
      height: 50px;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .albumLi:hover {
      cursor: pointer;
    }
    .active {
      border: 1px solid red;
    }
  }
}
</style>